<?php
	//session_start();
	//Defence so attacker won't be able to go to this page
/*	if((!isset($_SESSION['hallpass']))||($_SESSION['hallpass']==false))
	{
		$_SESSION['error'] = "not_auth";
		header('Location: error_page.php');
	}*/
	
class Connection
{
	var $fname;
	var $cred_arr;
	var $conn;
	
	
	/*connect to the db with the credintials from a file*/
	function Connection()
	{
		
		$this->fname = "cred.txt";
		$file=fopen($this->fname,"r");
		
		$i=0;
		while(!feof($file))
  		{
  			
  			$this->cred_arr[$i] = fgets($file);
  			//echo $i;
  			//echo $this->cred_arr[$i];
  			$i++;
  			
  		}
		fclose($file);
		$this->connect();	
	}
	
	
	function connect()
	{
		//$con = mysql_connect(chr($this->cred_arr[0]),chr($this->cred_arr[1]),"");
		
		$con = mysql_connect("localhost","root","");
		if (!$con)
  		{
  			die('Could not connect: ' . mysql_error());
  			//echo "fail";
  		}
  		else
  		{
  			//echo "Connection successful";
  			$this->conn = $con;
  			//mysql_select_db("workertrack",$con);
  			
  		}
	}
	

/*execute a SQL query*/	
	function execute_query($str)
	{
		mysql_select_db("workertrack",$this->conn);
		$result = mysql_query($str,$this->conn) 
			or die(mysql_error());  
		

			//echo "1 record added";
			
			return $result;
	}
	
	/*close connection to the db*/
	function close_connection()
	{
		mysql_close($this->conn);
	}
	
	
}


?>